package a05_ThreadInstance;

import javax.rmi.CORBA.StubDelegate;

/**
 * @Author quan
 * @Description 工厂模式
 * @Date 2023/5/10 17:05
 */
public class Factory {

}
class Student{
    private int id;
    private int age;
    private String name;

    public int getId() {
        return id;
    }
//    通过id和name属性构造一个学生对象
//    public Student(int id,String name){
//        this.id = id;
//        this.name = name;
//    }
//    报错：由于重载过程，参数列表相同而报错
//    通过age和name属性构造一个学生对象
//    public Student(int age, String name){
//        this.age = age;
//        this.name = name;
//    }
    //解决办法
    //通过id和name构造一个学生对象
    public static Student createByIdAndName(int id,String name){
        Student student = new Student();
        student.setId(id);
        student.setName(name);
        return student;
    }
    // 通过age 和 name 属性来构造一个学生对象
    public static Student createByAgeAndName (int age, String name) {
        Student student = new Student();
        student.setAge(age);
        student.setName(name);
        return student;
    }
    public void setId(int id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
